﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace ShotURL.Models
{
    public class DataManager
    {
        private shotUrlDBEntities _db;
        public string url;
        public  DataManager()
        {
            _db = new shotUrlDBEntities();
        }
        public IQueryable<InfoKey> GetInfoKey()
        {
            return _db.InfoKeys;
        }
        public IQueryable<ShotUrl> GetShotUrl()
        {
            return _db.ShotUrls;
        }
        public InfoKey GetInfoKey(Guid id)
        {
            return _db.InfoKeys.SingleOrDefault(item => item.InfoID == id);
        }
        public void SetClickUrl(Guid id)
        {
            InfoKey old = GetInfoKey(id);
            old.ClickShotUrl++;
            _db.SaveChanges();
        }
        public ShotUrl GetShotUrl(Guid id)
        {
            return _db.ShotUrls.SingleOrDefault(item => item.ShoturlId == id);
        }
        public void SetShotUrl(ShotUrl obj)
        {
            ShotUrl old = GetShotUrl(obj.ShoturlId);
            old.LongUrl = obj.LongUrl;
            old.ShotKey = obj.ShotKey;
            _db.SaveChanges();
        }
        public void AddShotUrl(ShotUrl obj)
        {
            _db.AddToShotUrls(obj);
            _db.SaveChanges();
        }
    }
}